package io.renren.modules.project.controller;

import java.util.List;
import java.util.Map;

import io.renren.common.annotation.SysLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.project.entity.ApplicantInfoEntity;
import io.renren.modules.project.service.ApplicantInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author tony Liu
 * @email 
 * @date 2018-11-22 16:47:52
 */
@RestController
@RequestMapping("/project/applicantinfo")
public class ApplicantInfoController {
	@Autowired
	private ApplicantInfoService applicantInfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("project:applicantinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<ApplicantInfoEntity> applicantInfoList = applicantInfoService.queryList(query);
		int total = applicantInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(applicantInfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("project:applicantinfo:info")
	public R info(@PathVariable("id") String id){
		ApplicantInfoEntity applicantInfo = applicantInfoService.queryObject(id);
		
		return R.ok().put("applicantInfo", applicantInfo);
	}
	
	/**
	 * 保存
	 */
	@SysLog("新增项目申请方")
	@RequestMapping("/save")
	@RequiresPermissions("project:applicantinfo:save")
	public R save(@RequestBody ApplicantInfoEntity applicantInfo){
		boolean isOk = applicantInfoService.save(applicantInfo);
		if (!isOk){
			return R.ok().put("code",1111);
		}
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@SysLog("修改项目申请方")
	@RequestMapping("/update")
	@RequiresPermissions("project:applicantinfo:update")
	public R update(@RequestBody ApplicantInfoEntity applicantInfo){
		boolean isOk = applicantInfoService.update(applicantInfo);
		if (!isOk){
			return R.ok().put("code",1111);
		}
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("project:applicantinfo:delete")
	public R delete(@RequestBody String[] ids){
		applicantInfoService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
